<?php
class Ajax extends CI_Controller{
	public function authenticate(){
		if ($this->session->userdata('user') == null) {
			echo "0";
		}else{
			echo "1";
		}
	}
	
	public function login(){
		$user = $this->input->post('user');
		$pass = $this->input->post('pass');
		
		
		$data = $this->User_model->select($user,$pass);
		if($data != NULL){
			$this->session->set_userdata('user',$data->ID);
			//
			echo "1";
		}else{
			echo "0";
		}
		
	}
	
	public function post($id){
		$data = $this->Post_model->getPostById($id);
		$json = json_encode($data);
		echo $json;
		
	}
	
	public function insertpost(){
		$title = $this->input->post('title');
		$text = $this->input->post('text');
		$category = $this->input->post('category');
		$parent_id = $this->input->post('parent');
		
		$result = $this->Post_model->insert($title,$text,$category,$parent_id);
		echo $result;
	}
	
	public function getChildCat($id){
		$data = $this->Category_model->getCategories($id);
		
		echo json_encode($data);
		exit;
	}
}